//
//  HRShoppingCartTableViewCell.m
//  haierapp
//
//  Created by Xia Zhiyong on 14-8-11.
//  Copyright (c) 2014年 haier. All rights reserved.
//

#import "HRShoppingCartTableViewCell.h"
#import "HRProductInfo.h"
#import "HRProSpeInfo.h"

@interface HRShoppingCartTableViewCell (){
    int currentNum;
    NSString* pId;
}

@end

@implementation HRShoppingCartTableViewCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = (HRShoppingCartTableViewCell *)[[[NSBundle mainBundle] loadNibNamed:@"HRShoppingCartTableViewCell"
                                                              owner:self
                                                            options:nil] objectAtIndex:0];
    [self setView];

    return self;
}

- (void)awakeFromNib
{
    [self setView];
}

-(void)setView{
    
  
    _viewBtnBg.layer.borderWidth = 1;
    _viewBtnBg.layer.borderColor = [UIColor colorFromHexRGB:@"b3b3b3"].CGColor;
    _viewBtnBg.layer.cornerRadius = 5;
    
}

-(void)configWithData:(id)data isSelected:(BOOL)isSelected{
    //init data
    _lblName.text=@"";
    _lblDetail.text=@"";
    _lblType.text=@"";
    _lblNum.text=@"";
    _lblPrice.text=@"";
    
    
    HRProductInfo *info = (HRProductInfo*)data;
    _btnSelect.selected = isSelected;
    pId = info.productId ;
    [_imgIcon setImageWithURL:[NSURL URLWithString:info.picMinPath]
                            placeholderImage:[UIImage imageNamed:IMAGENAME_PLACE_HODLE]];
    _lblName.text = [NSString stringWithFormat:@"%@",info.name];
    
    for (HRProSpeInfo *speInfo in info.proSpeInfo) {
        _lblDetail.text=[NSString stringWithFormat:@"%@%@:%@;",_lblDetail.text,speInfo.name,speInfo.value];
    }
   
    currentNum = [info.goodsAmount intValue];
    _lblNum.text = [NSString stringWithFormat:@"%d",currentNum];
    _lblPrice.text = [NSString stringWithFormat:@"%@",info.price];
    
    if ([info.isDX intValue]==1) {
        //小件
        _lblType.text=@"小件";
    }

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

}

- (IBAction)actionChoose:(id)sender {
    UIButton *btn = (UIButton*)sender;
    btn.selected = !btn.selected;
    if (_selectOrCancelPrdouct) {
        _selectOrCancelPrdouct(btn.selected,self);
    }
}

- (IBAction)actionChangeNum:(id)sender {
    UIButton *btn = (UIButton*)sender;
    if (btn.tag == 1000) {
        if (_numChange) {
            if (currentNum<=1) {
                _numChange(-1,nil); //提示数量无法再减
            }else {
                _numChange(1,pId);//减1
            }
        }
        
    }else{      //加1
        if (_numChange) {
            _numChange(0,pId);
            }
    }
    _lblNum.text = [NSString stringWithFormat:@"%d",currentNum];
}



@end
